// 设置wifi接入信息(请根据您的WiFi信息进行修改)

void connectWifi(void) // 连接wifi  需从tf卡读取
{
    WiFi.mode(WIFI_STA); //设置工作模式为无线终端模式

    // 设置静态ip
    unsigned short gateway_ID = (tf.readFileLine("/config/static_ip.txt", 1)).toInt(); // 网关统一ip
    delay(10);
    unsigned short gateway_num = (tf.readFileLine("/config/static_ip.txt", 2)).toInt(); // 网关ip号 一般为1
    delay(10);
    unsigned short local_IP_num = (tf.readFileLine("/config/static_ip.txt", 3)).toInt(); // 设备ip
    IPAddress local_IP(192, 168, gateway_ID, local_IP_num);                              //设备ip
    IPAddress gateway(192, 168, gateway_ID, gateway_num);                                //网关ip
    IPAddress subnet(255, 255, 255, 0);                                                  //子网掩码
    if (!WiFi.config(local_IP, gateway, subnet))
    {
        Serial.println("STA Failed to configure");
    }

    String ssid = tf.readFileLine("/config/wifi.txt", 1); // line-1 for WiFi ssid
    delay(10);
    String password = tf.readFileLine("/config/wifi.txt", 2); // line-2 for WiFi password
    WiFi.begin(ssid.c_str(), password.c_str());

    u8g2.clearBuffer(); //清屏
    //等待WiFi连接,成功连接后输出成功信息
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(1000);
        static String i = "";
        i += ".";
        if (i.length() > 5)
        {
            i = ".";
            u8g2.clearBuffer();
        }

        // 显示连接状态
        oled_print_module(0, 15, "Connect to " + String(ssid));
        oled_print_module(0, 30, i);
        u8g2.sendBuffer();
    }
    oled_print_single(0, 15, "IP:" + WiFi.localIP().toString());
    delay(1000);
}
